//
//  KGeneralDetailViewCell.m
//  Keping
//
//  Created by a on 2017/9/15.
//  Copyright © 2017年 柯平. All rights reserved.
//

#import "KGeneralDetailViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

#import "KGeneralDetailViewFrame.h"
@interface KGeneralDetailViewCell()
/**
 头像
 */
@property(nonatomic,weak)UIImageView*iconView;
/**
 昵称
 */
@property(nonatomic,weak)UILabel*nikeLabel;
/**
 内容
 */
@property(nonatomic,weak)UILabel*contentLabel;
/**
 时间
 */
@property(nonatomic,weak)UILabel*timeLabel;
/**
 评论按钮
 */
@property(nonatomic,weak)UIButton*commentBtn;
///**
// 评论数
// */
//@property(nonatomic,weak)UILabel*countLabel;
@end
@implementation KGeneralDetailViewCell


+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString*ID=@"KGeneralDetailViewCell";
    KGeneralDetailViewCell*cell=[tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell=[[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        //添加子控件
        [self setAddSubView];
    }
    return self;
}
-(void)setAddSubView
{
    //图片
    UIImageView*iconView=[[UIImageView alloc]init];
    [self.contentView addSubview:iconView];
//    iconView.backgroundColor=[UIColor redColor];
    self.iconView=iconView;
    
    //昵称
    UILabel*nikeLabel=[[UILabel alloc]init];
    [self.contentView addSubview:nikeLabel];
    nikeLabel.text=@"Heniry";
    nikeLabel.textColor=[UIColor colorWithHexString:@"#959595"];
    nikeLabel.font=HJFont(K_FactorW(17));
    self.nikeLabel=nikeLabel;
    
    //内容
    UILabel*contentLabel=[[UILabel alloc]init];
    [self.contentView addSubview:contentLabel];
    contentLabel.textColor=[UIColor colorWithHexString:@"101010"];
    contentLabel.text=@"Life is like a colorfu; chidhood dream, make a person yearn to make people yearning";
    contentLabel.font=HJFont(K_FactorW(17));
    contentLabel.numberOfLines=0;
    self.contentLabel=contentLabel;
    
    //时间
    UILabel*timeLabel=[[UILabel alloc]init];
    [self.contentView addSubview:timeLabel];
    timeLabel.textColor=[UIColor colorWithHexString:@"#d6d6d6"];
    timeLabel.font=HJFont(K_FactorW(13));
    timeLabel.text=@"3 hours ago";
    self.timeLabel=timeLabel;
    
    //评论按钮
    UIButton*commentBtn=[[UIButton alloc]init];
    [self.contentView addSubview:commentBtn];
    [commentBtn setImage:[UIImage imageNamed:@"comment"] forState:UIControlStateNormal];
    commentBtn.titleLabel.font = HJFont(K_FactorW(17));
    [commentBtn setTitleColor:[UIColor colorWithHexString:@"#aaaaaa"] forState:UIControlStateNormal];
    [commentBtn addTarget:self action:@selector(clickCommentBtn) forControlEvents:UIControlEventTouchUpInside];
    self.commentBtn=commentBtn;
    
    //评论数
//    UILabel*countLabel=[[UILabel alloc]init];
//    [self.contentView addSubview:countLabel];
//    countLabel.font=HJFont(K_FactorW(17));
//    countLabel.textColor=[UIColor colorWithHexString:@"#aaaaaa"];
//    countLabel.text=@"Comment";
//    self.countLabel=countLabel;
}
-(void)clickCommentBtn
{
    if ([_delegate respondsToSelector:@selector(generalDetailViewCellClickComment:)]) {
        [_delegate generalDetailViewCellClickComment:self.bbsPostsViews.id];
    }
}


- (void)layoutSubviews {
    [super layoutSubviews];
}

-(void)setBbsPostsViews:(KBbsPostsViews *)bbsPostsViews
{
    _bbsPostsViews = bbsPostsViews;
    
    //15 + 17 + 10 + _contentHeight + 17 + 13 + 20;
    
    CGFloat marginW =K_FactorW(12);
    CGFloat marginH= K_FactorH(15);
    CGFloat imgWH=K_FactorW(40);
    
    self.iconView.layer.cornerRadius = 20;
    self.iconView.layer.masksToBounds=YES;
    [self.iconView setFrame:CGRectMake(marginW, marginH, imgWH, imgWH)];
    [self.nikeLabel setFrame:CGRectMake(CGRectGetMaxX(self.iconView.frame) + 15, self.iconView.y, kScreenWidth - CGRectGetMaxX(self.iconView.frame) - 15 - 20, 17)];
    [self.contentLabel setFrame:CGRectMake(CGRectGetMinX(self.nikeLabel.frame), CGRectGetMaxY(self.nikeLabel.frame) + 10, CGRectGetWidth(self.nikeLabel.frame), bbsPostsViews.contentHeight)];
    [self.timeLabel setFrame:CGRectMake(CGRectGetMinX(self.nikeLabel.frame), CGRectGetMaxY(self.contentLabel.frame) + 10, 150, 13)];
    [self.commentBtn setFrame:CGRectMake(kScreenWidth - bbsPostsViews.countWidth - 45, self.timeLabel.y, bbsPostsViews.countWidth + 15, 17)];
//    [self.commentBtn setFrame:CGRectMake(self.countLabel.x - 15 - 14, self.countLabel.y, 14, 13)];
//    self.commentBtn.centerY = self.countLabel.centerY;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:[KGetImageURL stringByAppendingString:bbsPostsViews.profile]] placeholderImage:nil];
    self.nikeLabel.text = bbsPostsViews.realName;
    self.contentLabel.text = bbsPostsViews.content;
    self.timeLabel.text = bbsPostsViews.timeTitle;
    [self.commentBtn setTitle:bbsPostsViews.commontQty forState:UIControlStateNormal];
}
@end
